<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:c="http://java.sun.com/jsp/jstl/core">

<h:head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>Acesso Restrito</title>
	<h:outputStylesheet library="css" name="main.css" />
</h:head>

<h:body>
	<div class="esquerda">
		<h:form prependId="false">
			<p:button value="Registre-se" href="../publico/usuario.jsf"
				icon="ui-icon-person" />
			<p:button value="Ajuda" href="#" icon="ui-icon-info" />
		</h:form>
	</div>

	<p:dialog header="Login" visible="true" closable="false"
		draggable="false" resizable="false" width="250" showEffect="slide">
		<h:form id="login-form" prependId="false">

			<c:if test="${!empty param.login_error}">
				<p:growl>
					<f:event type="preRenderComponent" listener="#{growCtrl.preRender}" />
					<f:attribute name="error"
						value="${SPRING_SECURITY_LAST_EXCEPTION.message}" />
				</p:growl>
			</c:if>

			<p:focus for="Usuario" />

			<h:panelGrid id="login-grid" columns="3">

				<p:outputLabel for="Usuario" value="Usuario:" />
				<p:inputText id="Usuario" value="#{loginView.userName}"
					required="true" />
				<p:message for="Usuario" display="tooltip" />

				<p:outputLabel for="Senha" value="Senha:" />
				<p:inputText type="password" id="Senha"
					value="#{loginView.password}" required="true" />
				<p:message for="Senha" display="tooltip" />

				<p:outputLabel for="Remember" />
				<p:selectBooleanCheckbox value="#{loginView.remember}" id="Remember"
					itemLabel="Lembrar-me?" />

			</h:panelGrid>

			<p:row>
				<p:outputPanel style="width:100%; text-align:center" layout="block">
					<p:growl id="growl" sticky="false" />
					<p:commandButton value="Login" icon="ui-icon-check" process="@form"
						update="growl,login-grid" actionListener="#{loginView.login}" />
				</p:outputPanel>
			</p:row>

		</h:form>

	</p:dialog>

	<form id="hidden-form" style="display: none;"
		action="#{request.contextPath}/j_spring_security_check" method="post">
		<fieldset>
			<input id="j_username" type="hidden" name="j_username"></input> <input
				id="j_password" type="hidden" name="j_password"></input> <input
				id="_spring_security_remember_me" type="hidden"
				name="_spring_security_remember_me"></input>
		</fieldset>
	</form>

	<script type="text/javascript">
    function mysubmit() {
        $('#j_username').val($('#Usuario').val());
        $('#j_password').val($('#Senha').val());
        $('#_spring_security_remember_me').val($('#Remember').val());
        
        $('#hidden-form').submit();
    }
	</script>

	<script>
		document.getElementById("login-form").Usuario.value = "#{SPRING_SECURITY_LAST_USERNAME}";
 	</script>
</h:body>
</html>
